/**
 * 
 */
package com.cyou.qb.common.dao;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.cyou.nad.dao.PojoPage;
import com.cyou.qb.common.domain.UserWinner;
import com.cyou.qb.common.domain.Winner;
import com.cyou.qb.common.domain.WinnerContract;

/**
 * @author zoudongchao
 *
 */
@Component
public class WinnerDao extends MysqlBaseDao {
	public List<Winner> findWinnerByConditions(int activeId, int awardId, Date startTime, Date endTime) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("activeId", activeId);
		params.put("awardId", awardId);
		params.put("startTime", startTime);
		params.put("endTime", endTime);
		
		return this.getListByEntity("findWinnerByIdAndTimeZone", params);
	}
	
	public List<Winner> findWinnerByConditions(int activeId, int awardId, Date startTime) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("activeId", activeId);
		params.put("awardId", awardId);
		params.put("startTime", startTime);
		
		return this.getListByEntity("findWinnerByIdAndTimeZone", params);
	}
	
	public int addOneWinner(Winner winner){
		return this.insert("addOneWinner", winner);
	}
	
	@SuppressWarnings("unchecked")
	public PojoPage<UserWinner> getUserWinnerList(String passport,int pageNo, int pageSize){
		return this.getPage(passport, pageNo, pageSize);
	}
	/**
	 * Description 根据虚拟物品明细id获取winner数量
	 * 
	 * @author lidongwei
	 * @since 2012-10-16
	 */
	public int getWinnerCountByVirId(Integer virtualId) {
		return this.getCount("getWinnerCountByVirId", virtualId);
	}
	
	
	public int saveWinnerContract(WinnerContract contract){
		return this.insert("addWinnerContract", contract);
	}

	/**
	 * Description  检测此奖品是否已经有中奖信息
	 * @author lidongwei
	 * @since 2012-10-24
	 */
	public boolean checkDrawAward(Integer activeId, Integer awardId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("activeId", activeId);
		params.put("awardId", awardId);
		int count = this.getCount("getDrawAwardCount", params);
		if(count>0){
			return true;
		}
		return false;
	}

}
